﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="TestGetAt.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Mathematics.LinearAlgebra.Sequential.Tests.DenseVectorTest
{
    #region Usings

    using System;

    using ExulLibrary.Exceptions;

    using NUnit.Framework;

    #endregion

    /// <summary>
    ///     Test suite for <see cref="DenseVectorExtensions.GetAt{T}"/>.
    /// </summary>
    [TestFixture]
    [Category("ExulLibrary.Mathematics.LinearAlgebra.Sequential.DenseVectorExtensions")]
    public sealed class TestGetAt
    {
        /// <summary>
        ///     Tests the method when index parameter is less than the length of vector and non-negative.
        /// </summary>
        /// <param name="index">The zero-based index of element.</param>
        [Test]
        public void WhenIndexIsValid([Values(0, 1, 2)] int index)
        {
            // Arrange
            var data = new[] { new object(), new object(), new object() };
            var vector = new DenseVector<object>(data);

            // Act
            var result = vector.GetAt(index);

            // Assert
            Assert.That(result, Is.SameAs(data[index]));
        }

#if SAFE

        /// <summary>
        ///     Tests the method when index parameter is negative or greater than or equal to the number of elements of vector.
        /// </summary>
        /// <param name="index">The index of element.</param>
        [Test]
        public void WhenIndexIsOutOfExpectedRange([Values(-1, 3)] int index)
        {
            // Arrange
            var vector = new DenseVector<object>(3);

            // Act and Assert
            Assert.That(
                () => vector.GetAt(index),
                Throws.TypeOf<ElementIndexIsOutOfRangeException>().With.Property("ParamName").EqualTo("index"));
        }

        /// <summary>
        ///     Tests the method when vector parameter is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenVectorIsNull()
        {
            // Act and Assert
            Assert.That(
                () => DenseVectorExtensions.GetAt<object>(null, 0),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("vector"));
        }

#endif
    }
}